package com.brainydroid.items;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.brainydroid.framework.Object;


public class Button extends Object {

	int color_;
	
	public Button() {
	}

	
	public Button(float x, float y, float w, float h, int color) {
		touchable_ = true;
		setPosition(x,y);
		setDimensions(w,h);
		setColor(color);
	}

	
	private void setColor(int color) {
		color_ = color;		
	}

	public void setTxtreg(	TextureRegion tr)
	{
		addSingleFrame(tr);		
	}
	
	public void changeTxtreg(	TextureRegion tr)
	{
		animations_.get(0).frames_.get(0).texreg_ = tr;		
	}
	
	@Override
	public boolean istouch(float x,float y,float sx, float sy){
		return (x >= getScreenx() && x <= getScreenx()+widthOnScreen() && y >= getScreeny() && y <= getScreeny()+heightOnScreen());
	//	return (x >= this.getAbsx() && x <= this.getAbsx()+this.width_ && y >= this.getAbsy() && y <= this.getAbsy()+this.height_);
	}

	@Override
	protected void onTouchDown() {
		// TODO Auto-generated method stub
		touched_ = true;
		
		
	}

	@Override
	protected void onTouchUp() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onTouchLong() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onTouchDrag(float x, float y) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void update(float deltatime) {
		// TODO Auto-generated method stub
		
	}

	
	
	/**
	 * Checks if button was touched. If so, return true and set button to untouched
	 * @return
	 */
	public boolean checktouched(){
		if (touched_){
			touched_ = false;
			return true;
		}else{
			return false;
		}
	}


	public void center() {
		setPosition((float)Gdx.graphics.getWidth()/2-width_/2, (float)Gdx.graphics.getHeight()/2-height_/2);
	}
	

}
